from django.db import models

from product.models import *


# Create your models here.
class User(models.Model):
    name = models.CharField('用户名', max_length=20, null=True)
    password = models.CharField('密码', max_length=100)
    vip = models.BooleanField('是否开通会员', blank=False, default=False)
    addr = models.CharField('家庭住址', max_length=1000, default='')
    tel = models.CharField('电话号码', max_length=12, default='')
    email = models.EmailField('邮箱', default='123456@qq.com')

    def __str__(self):
        return self.name


# 订单
class Order(models.Model):
    order_num = models.CharField(max_length=20)
    user = models.ForeignKey(User, on_delete=True)
    product = models.ForeignKey(Product, on_delete=True)
    all_num = models.IntegerField(blank=True)
    create_time = models.DateField(auto_now_add=True)

    def __str__(self):
        return self.order_num

    def save(self, force_insert=False, force_update=False, using=None,
             update_fields=None):
        super(Order, self).save()
        prize = ''
